# Contributor: wener <wenermail@gmail.com>
# Maintainer: wener <wenermail@gmail.com>
pkgname=n2n
pkgver=3.1.1
pkgrel=1
pkgdesc="Peer-to-peer VPN"
url="https://github.com/ntop/n2n"
arch="all"
license="GPL-3.0-only"
makedepends="cmake openssl-dev>3 libcap-dev samurai"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc $pkgname-doc"
source="https://github.com/ntop/n2n/archive/$pkgver/n2n-$pkgver.tar.gz
	supernode.initd
	supernode.confd
	edge.initd
	edge.confd
	"
# source do not contain check
options="!check"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS .
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -m644 -D "$builddir"/packages/etc/n2n/supernode.conf.sample "$pkgdir"/etc/n2n/supernode.conf
	install -m644 -D "$builddir"/packages/etc/n2n/edge.conf.sample "$pkgdir"/etc/n2n/edge.conf
	install -m755 -D "$srcdir"/supernode.initd "$pkgdir"/etc/init.d/supernode
	install -m644 -D "$srcdir"/supernode.confd "$pkgdir"/etc/conf.d/supernode
	install -m755 -D "$srcdir"/edge.initd "$pkgdir"/etc/init.d/edge
	install -m644 -D "$srcdir"/edge.confd "$pkgdir"/etc/conf.d/edge

}

sha512sums="
ba4ffbc758c399758e35b47308a663f33d04ecb9595f296fd77b13631cea08e04a7cd7369fe82e09149a31e145cd25610dd0a387853ec149e479df866b778cb6  n2n-3.1.1.tar.gz
c771f85a04ded9d1c1a191f4c3f43fa1f760fe4899d64953ed4c1ac2dcbd864813879c99e567ffe6be8604727c243f391ebd52c3bc1484aca70c1c9964aa2835  supernode.initd
df2eff2cdf11e233d187c52a7dcb039aebaa3b87ef6a12449955097bc5c17c65e4b8241e8700bdbb7d186548c4cc8d99f9cb51ba017a9f71cc8483270fa2ff4d  supernode.confd
7d12adc2b376e245e8727609d11effc6e6020c3dd501a46c6a35224d49519b30e0e052c439ee16c21363147ae48057c0511e5b15268974b2271265e67221a4b5  edge.initd
2b96db736ecb5e636c44c4230671ca84175c90d19586967aa272bd7cf785126223a1fa2938b66a016b61a917aafcc20d9047d7109d40fb912e89ca3de24ae243  edge.confd
"
